<?php


$g4_path = '../';
$lib =  "$g4_path/lib.php";
$menu = 7;
require_once ("$g4_path/common.php");
require_once ($lib);
require_once ('../lib/Template_.class.php');

require_once ('./mydesk.lib.php');
require_once('../head.ebvill.php');

$tpl = new Template_;
$tpl->template_dir = './tpl';
$tpl->compile_dir = './tpl/compile';

if(isset($_GET['mode']) && $_GET['mode'] == "logout") {
    session_unregister("isParent"); 
}

if(isset($_POST['passwd']) && $_POST['mode'] == "login") {
    
    $_temp = sql_fetch("SELECT mb_code FROM g4_member WHERE `mb_id`='$userid' LIMIT 1"); 
    if($_temp['mb_code'] === $_POST['passwd'])  {
        session_register("isParent");
        $_SESSION['isParent']= TRUE;
    } else {
        alert("비밀번호가 일치하지 않습니다. 다시 확인해주세요.");
    }
}

if(!$_SESSION['isParent']) {
    $tpl->define('basic',"myCourseValuationLogin.html");
    $tpl->print_('basic');
} else {

$year = isset($_GET['year'])? $_GET['year'] : date('Y');
$month = isset($_GET['month'])? $_GET['month'] : date('n');
$data = $_tplSetting = array();

$nowPage = isset($_GET['page']) ? $_GET['page'] : 1; 
$perPage = 10;

$_sqlWhere = _makeSqlWhere($_sqlWhere, 'c.year', $year);
$_sqlWhere = _makeSqlWhere($_sqlWhere, 'c.month', $month);
$_sqlWhere = _makeSqlWhere($_sqlWhere, 'c.student', $studentno);
$_sqlWhere = _makeSqlWhere($_sqlWhere, 'cr.no', 'c.course');

$_res = sql_fetch("SELECT count(c.no) as cnt FROM coursevaluation c, course cr ".$_sqlWhere);
$totalPage = ceil($_res['cnt']/$perPage);

if(( ($nowPage > $totalPage) && $nowPage > 1) || ($nowPage < 1)) {
    alert("페이지 번호가 잘못되었습니다.");
}
$_sqlLimitPage = ($nowPage-1)*$perPage; 
$_sqlOrder = " ORDER BY c.no DESC"; 
$_sqlLimit = " LIMIT $_sqlLimitPage, $perPage"; 
$_sqlWhere = _makeSqlWhere($_sqlWhere, 'cr.teacher', 'm.mb_no');
$sql = 'SELECT c.*, m.mb_name as teachername FROM coursevaluation c, course cr, g4_member m '.$_sqlWhere.$_sqlOrder.$_sqlLimit;

$scoreArray = array('0'=>'', '1'=>'하','5'=>'중','10'=>'상');
$_res = sql_query($sql);
while($_ret = sql_fetch_array($_res)) {
    $_ret['memo'] = htmlspecialchars(stripslashes($_ret['memo'])); 
    $_ret['date'] = print00($_ret['date']); 
    $_ret['month'] = print00($_ret['month']); 
    $_ret['pron'] = $scoreArray[$_ret['pron']]; 
    $_ret['voca'] = $scoreArray[$_ret['voca']]; 
    $_ret['conv'] = $scoreArray[$_ret['conv']]; 
    $_ret['gram'] = $scoreArray[$_ret['gram']]; 
    $data[] = $_ret; 
}

$thisYear = date('Y');
for($i = 2008; $i <= $thisYear+1; $i++) {
        $years[$i]= array('y' => "{$i}년");
        if($i == $_GET['year']) {
            $years[$i]['s'] = 'selected="selected"';
        }
}

$monthSelected = array($_GET['month']=>'selected="selected"');


if(!$totalPage) {
    $_tplSetting['nodata'] = TRUE; 
}
$_tplSetting['paging'] = get_paging($perPage,$nowPage,$totalPage,"./myCourseValuation.php?page=",makelink(array('page')));
$tpl->assign('data', $data);
$tpl->assign('set', $_tplSetting);
$tpl->define('basic',"myCourseValuation.html");
$tpl->print_('basic');

}
